package com.admin.config.db.properties;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;

@Configuration
public class ProfileConfig {
    /**
     * @return
     * @PropertySource 不支持 yml格式，需要自己手动加载
     */
    @Bean
    public static PropertySourcesPlaceholderConfigurer properties() {
        PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
        YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
//        System.out.println(StringUtils.cleanPath("/resources/application-druid.yml"));
//        yaml.setResources(new FileSystemResource("D:\\gitLib\\java_develop\\first-app-demo\\permission\\src\\main\\resources\\application-druid.yml"));//File引入
        yaml.setResources(new ClassPathResource("application-druid.yml"));//class引入
                configurer.setProperties(yaml.getObject());
        return configurer;
    }
}
